package cn.egame.extraction.util;

import java.util.Properties;

import cn.egame.common.util.Utils;

public class ConstVar_EFS {
    public static String MAX_ID_FILE_PATH;
    public static String DAY_FILE_PATH;
    public static String FETCH_ERROR_IDS_FILE_PATH;
    public static String CONNECT_ERROR_IDS_FILE_PATH;
    public static String REFETCH_ERROR_IDS_FILE_PATHS = "";
    public static String MAX_ID_URL;
    public static String DNS_HOST;
    public static String EFS_TYPE = "";
    public static String NUM;
    // public static String LOCAL_FILE_PATH;
    public static int REPEAT_READ_NUM;
    public static int END_ID;
    public static String DAY_FILE_TYPE = "";

    public static String UPLOAD_ADDRESS;
    public static String UPLOAD_WRITE_ADDRESS;

    // thread configure

    public static int BLOCK_SIZE;

    public static int MAXIMUM_POOL_SIZE;

    public static long KEEP_ALIVE_TIME;

    public static int CORE_POOL_SIZE;
    // sleep_time_m_second
    public static int SLEEP_TIME_M_SECOND;

    // timer task
    public static long SCHEDULE_DELAY;
    public static long SCHEDULE_PERIOD;

    // 初始化加载

    public static boolean IS_INIT = false;

    // 多线程睡眠时间
    public static int MULTI_SLEEP_TIME;

    // 定时同步程序
    public static String TXT_SOURCE;

    public static String TXT_TARGET;
    
    //初始化目录树写入路径
    public static String INIT_FILE_PATH;
    
    //读取文件的时间戳在10分钟之前
    
    public static long TIME_STEP;
    
    //每次同步文件的间隔时间
    
    public static long PROCESS_PER_TIME;

    static {
        Properties properties = getProperties();
        MAX_ID_FILE_PATH = getPropertiesValueByKey(properties, "max_id_file_path", MAX_ID_FILE_PATH);
        System.out.println("max_id_file_path========" + MAX_ID_FILE_PATH);

        DAY_FILE_PATH = getPropertiesValueByKey(properties, "day_file_path", DAY_FILE_PATH);
        System.out.println("day_file_path========" + DAY_FILE_PATH);

        FETCH_ERROR_IDS_FILE_PATH = getPropertiesValueByKey(properties, "fetch_error_ids_file_path", FETCH_ERROR_IDS_FILE_PATH);
        System.out.println("fetch_error_ids_file_path========" + FETCH_ERROR_IDS_FILE_PATH);

        CONNECT_ERROR_IDS_FILE_PATH = getPropertiesValueByKey(properties, "connect_error_ids_file_path", CONNECT_ERROR_IDS_FILE_PATH);
        System.out.println("connect_error_ids_file_path========" + CONNECT_ERROR_IDS_FILE_PATH);

        REFETCH_ERROR_IDS_FILE_PATHS = getPropertiesValueByKey(properties, "refetch_error_ids_file_paths", REFETCH_ERROR_IDS_FILE_PATHS);
        System.out.println("refetch_error_ids_file_path========" + REFETCH_ERROR_IDS_FILE_PATHS);

        MAX_ID_URL = getPropertiesValueByKey(properties, "max_id_url", MAX_ID_URL);
        System.out.println("max_id_url========" + MAX_ID_URL);

        DNS_HOST = getPropertiesValueByKey(properties, "dns_host", DNS_HOST);
        System.out.println("dns_host========" + DNS_HOST);

        EFS_TYPE = getPropertiesValueByKey(properties, "efs_type", EFS_TYPE);
        System.out.println("efs_type========" + EFS_TYPE);

        NUM = getPropertiesValueByKey(properties, "num", NUM);
        System.out.println("num========" + NUM);

        // LOCAL_FILE_PATH = getPropertiesValueByKey(properties,
        // "local_file_path", LOCAL_FILE_PATH);
        // System.out.println("local_file_path========"+LOCAL_FILE_PATH);

        REPEAT_READ_NUM = getPropertiesIntValueByKey(properties, "repeat_read_num", REPEAT_READ_NUM);
        System.out.println("repeat_read_num========" + REPEAT_READ_NUM);

        END_ID = getPropertiesIntValueByKey(properties, "end_id", END_ID);
        System.out.println("end_id========" + END_ID);

        DAY_FILE_TYPE = getPropertiesValueByKey(properties, "day_file_type", DAY_FILE_TYPE);
        System.out.println("day_file_type========" + DAY_FILE_TYPE);

        /* upload_address 获取 */
        UPLOAD_ADDRESS = getPropertiesValueByKey(properties, "upload_address", UPLOAD_ADDRESS);
        System.out.println("upload_address========" + UPLOAD_ADDRESS);

        /* upload_address 获取 */
        UPLOAD_WRITE_ADDRESS = getPropertiesValueByKey(properties, "upload_write_address", UPLOAD_WRITE_ADDRESS);
        System.out.println("UPLOAD_WRITE_ADDRESS========" + UPLOAD_WRITE_ADDRESS);

        BLOCK_SIZE = getPropertiesIntValueByKey(properties, "block_size", BLOCK_SIZE);
        System.out.println("BLOCK_SIZE==========" + BLOCK_SIZE);
        MAXIMUM_POOL_SIZE = getPropertiesIntValueByKey(properties, "maximum_pool_size", MAXIMUM_POOL_SIZE);
        System.out.println("MAXIMUM_POOL_SIZE=========" + MAXIMUM_POOL_SIZE);
        KEEP_ALIVE_TIME = getPropertiesLongByKey(properties, "keep_alive_time", KEEP_ALIVE_TIME);
        System.out.println("KEEP_ALIVE_TIME===========" + KEEP_ALIVE_TIME);
        CORE_POOL_SIZE = getPropertiesIntValueByKey(properties, "core_pool_size", CORE_POOL_SIZE);
        System.out.println("CORE_POOL_SIZE=========" + CORE_POOL_SIZE);

        SLEEP_TIME_M_SECOND = getPropertiesIntValueByKey(properties, "sleep_time_m_second", SLEEP_TIME_M_SECOND);
        System.out.println("SLEEP_TIME_M_SECOND========" + SLEEP_TIME_M_SECOND);
        SCHEDULE_DELAY = getPropertiesLongByKey(properties, "schedule_delay", SCHEDULE_DELAY);
        System.out.println("SCHEDULE_DELAY==========" + SCHEDULE_DELAY);
        SCHEDULE_PERIOD = getPropertiesLongByKey(properties, "schedule_period", SCHEDULE_PERIOD);
        System.out.println("SCHEDULE_PERIOD========" + SCHEDULE_PERIOD);
        MULTI_SLEEP_TIME = getPropertiesIntValueByKey(properties, "multi_sleep_time", MULTI_SLEEP_TIME);
        System.out.println("MULTI_SLEEP_TIME========" + MULTI_SLEEP_TIME);
        IS_INIT = Boolean.valueOf(getPropertiesValueByKey(properties, "is_init", "false"));
        System.out.println("is_init========" + IS_INIT);
        TXT_SOURCE = String.valueOf(getPropertiesValueByKey(properties, "txt_source", ""));
        System.out.println("TXT_SOURCE========" + TXT_SOURCE);
        TXT_TARGET = String.valueOf(getPropertiesValueByKey(properties, "txt_target", ""));
        System.out.println("TXT_TARGET========" + TXT_TARGET);
        INIT_FILE_PATH=String.valueOf(getPropertiesValueByKey(properties, "int_file_path", ""));
        System.out.println("INIT_FILE_PATH========" + INIT_FILE_PATH);
        TIME_STEP = getPropertiesLongByKey(properties, "time_step", TIME_STEP);
        System.out.println("TIME_STEP========" + TIME_STEP);
        PROCESS_PER_TIME = getPropertiesLongByKey(properties, "process_per_time", PROCESS_PER_TIME);
        System.out.println("PROCESS_PER_TIME========" + PROCESS_PER_TIME);
    }

    private static String getPropertiesValueByKey(Properties properties, String key, String defaultResult) {
        /* download_url 获取 */
        String value = properties.getProperty(key);
        if (value != null && !"".equals(value.trim())) {
            return value;
        }
        return defaultResult;
    }

    private static int getPropertiesIntValueByKey(Properties properties, String key, int defaultResult) {
        /* download_url 获取 */
        String value = properties.getProperty(key);
        if (value != null && !"".equals(value.trim()) && value.matches("[-]?\\d+")) {
            return Integer.parseInt(value);
        }
        return defaultResult;
    }

    private static long getPropertiesLongByKey(Properties properties, String key, long defaultResult) {
        /* download_url 获取 */
        String value = properties.getProperty(key);
        if (value != null && !"".equals(value.trim()) && value.matches("[-]?\\d+")) {
            return Long.parseLong(value);
        }
        return defaultResult;
    }

    private static Properties getProperties() {
        Properties properties = new Properties();
        try {
            properties = Utils.getProperties("common.properties");
        } catch (Exception e) {
            System.out.println("common.properties not find");
        }
        return properties;
    }

    public static void main(String[] args) {
        System.out.println("".matches("[-]?\\d+"));

    }
}
